import service from './axios.js'
import $config from '../../public/config.js'
import $notify from '../utils/notify.js'

const baseURL = $config.baseURL

/**
 * 请求配置
 * @param {String} method [可选]请求名称，通过 $api[name]()调用，默认使用请求的url作为请求名称(去掉‘/’)
 * @param {String} url 请求地址
 * @param {String} location [可选]请求域名，默认为$config.baseURL域名
 * @example
**/
const requestConfig = {
  get: [
    { /* method: 'getId', */ url: `/getId` }
  ],
  post: [
    { method: 'getMockDataById', url: `/getDataById` }
  ]
}

let requestList = {}

Object.keys(requestConfig).map((key) => {
  requestConfig[key].map((item) => {
    const { method, url, location } = item
    requestList[method ?? url.slice(1)] = params => service[key](`${location || baseURL}${url}`, { params })
  })
})

console.log('%c%s', 'color:green;', '[api.js] api请求配置: ', requestList)

export default {
  ...$config,
  ...$notify,
  ...requestList
}